[#ftl]

[#assign datetimeformat="MMM dd yyyy HH:mm"]

[#macro propvalue value type]
[#-- TODO: this is a workaround --]
[#assign value2 = value?replace('<cmis:value xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200901">', '')?replace('</cmis:value>', '')]
[#if type == "string"]
[@stringvalue value2/]
[#elseif type == "integer"]
[@integervalue value2/]
[#elseif type == "decimal"]
[@decimalvalue value2/]
[#elseif type == "boolean"]
[@booleanvalue value2/]
[#elseif type == "datetime"]
[@datetimevalue value2/]
[#elseif type == "date"]
[@datetimevalue value2/]
[#elseif type == "uri"]
[@urivalue value2/]
[#elseif type == "id"]
[@idvalue value2/]
[#else]
${value}
[#-- TODO: remaining property types --]
[/#if]
[/#macro]

[#macro stringvalue value]${value?string}[/#macro]
[#macro integervalue value]${value}[/#macro]
[#macro decimalvalue value]{value}[/#macro]
[#macro booleanvalue value]${value?string}[/#macro]
[#macro datetimevalue value]${xmldate(value?string)?datetime}[/#macro]
[#macro urivalue value]${value}[/#macro]
[#macro idvalue value]${value}[/#macro]

[#macro proxyurl url endpoint endpointurl]
${url?replace(endpointurl,"/proxy/"+endpoint)}
[/#macro]

[#-- Document List View Template --]

[#macro doclist entries view endpoint endpointurl]

	[#if view='full']
		Showing ${entries?size} Results:<br/>

		[#assign index=0]
		<table border="1" style="border-style: solid;border-collapse: collapse;">

			[#list entries as entry]
			
				  [#assign cmis_object=entry.getExtension(atom.names.cmis_object)]
				  [#assign noOfProperties = cmis_object.properties.names?size]
				  [#list cmis_object.properties.names?chunk(noOfProperties) as row]
				  [#if index=0]
					<tr>
					  [#list row as propname]
						<th>${propname} (${cmis_object.properties.find(propname).type})</th>
					  [/#list]
					</tr>
				  [/#if]
					<tr>
					[#list row as propname]
					  <td>[#if cmis_object.properties.find(propname).type == "uri"]
							   <a href="[@cmisutils.propvalue cmis_object.properties.find(propname).value!'NULL' cmis_object.properties.find(propname).type!"NO TYPE"/]" target="_new">[@cmisutils.propvalue cmis_object.properties.find(propname).value!"NULL" cmis_object.properties.find(propname).type!"NO TYPE"/]</a>
					  [#else]
							   [@cmisutils.propvalue cmis_object.properties.find(propname).value!"NULL" cmis_object.properties.find(propname).type!"NO TYPE"/]
					  [/#if]
					  </td>
					[/#list]
					</tr>
				  [/#list]

				  [#assign index=1]

			[/#list]

		</table>
		
	[/#if]
	[#if view='details']		
		[#list entries as entry]
			[@docview entry view endpoint endpointurl/]
		[/#list]
	[/#if]	
	[#if view='list']		
		[#list entries as entry]
			[@docview entry view endpoint endpointurl/]
		[/#list]
	[/#if]	
	[#if view='thumbnail']		
		[#list entries as entry]
			[@docview entry view endpoint endpointurl/]
		[/#list]
	[/#if]	
[/#macro]

[#macro docview entry view endpoint endpointurl]

	[#if view='full']

		[#assign cmis_object=entry.getExtension(atom.names.cmis_object)]
		[#assign noOfProperties = cmis_object.properties.names?size]
		
		<table border="1" style="border-style: solid;border-collapse: collapse;">		
			[#list cmis_object.properties.names?chunk(noOfProperties) as row]			
				[#list row as propname]				
					<tr>
					  <td>${propname}</td>
					  <td>[#if cmis_object.properties.find(propname).type == "uri"]
							   <a href="[@cmisutils.propvalue cmis_object.properties.find(propname).value!'NULL' cmis_object.properties.find(propname).type!"NO TYPE"/]" target="_new">[@cmisutils.propvalue cmis_object.properties.find(propname).value!"NULL" cmis_object.properties.find(propname).type!"NO TYPE"/]</a>
					  [#else]
							   [@cmisutils.propvalue cmis_object.properties.find(propname).value!"NULL" cmis_object.properties.find(propname).type!"NO TYPE"/]
					  [/#if]
					  </td>
					</tr>
				[/#list]
			[/#list]		
		</table>

	[/#if]	
	[#if view='details']
		[#assign cmis_object=entry.getExtension(atom.names.cmis_object)]
		[#assign alf_icon=entry.getSimpleExtension("http://www.alfresco.org","icon","alf")]
		<div>
			<img src="${alf_icon}"/><a href="[@proxyurl entry.contentSrc endpoint endpointurl/]" target="_new">${cmis_object.name.value}</a> Size: ${(cmis_object.contentStreamLength.integerValue/1024)?string(",##0.00")} K By ${cmis_object.lastModifiedBy.value} @ ${cmis_object.lastModificationDate.dateValue?datetime}
		</div>
	[/#if]
	[#if view='list']
		[#assign cmis_object=entry.getExtension(atom.names.cmis_object)]
		[#assign alf_icon=entry.getSimpleExtension("http://www.alfresco.org","icon","alf")]
		<div>
			<a href="[@proxyurl entry.contentSrc endpoint endpointurl/]" target="_new">${cmis_object.name.value}</a>
		</div>
	[/#if]
	[#if view='thumbnail']
		[#assign cmis_object=entry.getExtension(atom.names.cmis_object)]
		[#assign alf_icon=entry.getSimpleExtension("http://www.alfresco.org","icon","alf")]
		
		[#if entry.selfLink.href?? && entry.contentSrc?? ]
			<div style="margin-bottom: 10px;">
				<div style="float:left;width: 15%;">
					<img src="[@proxyurl entry.selfLink.href endpoint endpointurl/]/content/thumbnails/doclib"/>
				</div>
				<div style="float:right;width : 85%">
					<a href="[@proxyurl entry.contentSrc endpoint endpointurl/]" target="_new">${cmis_object.name.value}</a>
					<br/>Size: ${(cmis_object.contentStreamLength.integerValue/1024)?string(",##0.00")} K
					<br/>By: ${cmis_object.lastModifiedBy.value}
					<br/>Last Modified: ${cmis_object.lastModificationDate.dateValue?datetime}
					<br/>Description: ${entry.summary}
				</div>
				<div style="clear:both"></div>
			</div>
		[/#if]
	[/#if]
[/#macro]

[#-- Activity List View Template --]

[#macro activities feed]
	<div style="font-weight:bold">${feed.title}</div>
	[#list feed.entries as entry]
		<div style="margin:10px">
			<div>${entry.title}</div>
			<div style="">${entry.updated?datetime}</div>
			<div>${entry.summary}</div>			
		</div>
	[/#list]
[/#macro]
